import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { demoAction } from '@/reducers/demoReducer';
import { Button, Toast, SearchBar } from 'antd-mobile';
import { connect } from 'react-redux';
import { serveTest } from '@/service/request';
import { MESSAGE_MUTATION } from '@/constant/prompt';
import './style.scss';

class Demo extends Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    action = () => {
        this.props.dispatch(demoAction());
    };
    request = async () => {
        try {
            await serveTest();
        } catch (e) {
            Toast.fail(e.msg, MESSAGE_MUTATION);
        }
    };
    render() {
        return (
            <div>
                <SearchBar placeholder="输入" maxLength={8} />
                <Button type="ghost" className='btn-style' onClick={this.action}>Action</Button>
                <Button type="primary" onClick={this.request}>Request</Button>
                <div className='div-style'></div>
            </div>
        );
    }
}
Demo.propTypes = {
    dispatch: PropTypes.func,
};
export default connect((state) => ({
    demoData: state.demoReducer.demoData,
}))(Demo);


